package com.sicheng.lc.杂题.二叉树;

import leetcode.editor.cn.tree.TreeNode;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/8/2 20:50
 */
public class 把二叉搜索树转换为累加树 {
    //https://leetcode.cn/problems/convert-bst-to-greater-tree/
    int sum = 0;

    public TreeNode convertBST(TreeNode root) {
        convert(root);
        return root;
    }

    void convert(TreeNode root) {
        if (root == null)
            return;

        convert(root.right);
        sum += root.val;
        root.val = sum;
        convert(root.left);

    }
}
